package com.zhangye.test.util;

import com.alibaba.fastjson.JSONObject;

public class AddressUtil {
	
	
	public static String getRegionByLocation(String location) {
        String key = "ff53d41333699e71213e01ed52a73761";
        String url = String.format("http://restapi.amap.com/v3/geocode/regeo?key=%s&location=%s&poitype=&radius=&extensions=all&batch=false&roadlevel=", key, location);
        String content = HttpUtil.requestGet(url);
        JSONObject json = JSONObject.parseObject(content);
        if ("1".equalsIgnoreCase(json.getString("status"))) {//正常
            JSONObject a = json.getJSONObject("regeocode").getJSONObject("addressComponent");

            String district = a.getString("district");
            String province = a.getString("province");
            String city = a.getString("city");
            return province + city + district;
        }
        return null;
    }
}
